const common = require("./webpack.common")
const { merge } = require("webpack-merge")
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require("copy-webpack-plugin")
const TerserPlugin = require("terser-webpack-plugin")
const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin")
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')


module.exports = merge(common, {
    mode: "production",
    optimization: {
        // 只输出引用代码
        usedExports: true,
        // 压缩输出文件
        minimize: true,
        // 尽可能将所有模块合并输出到一个函数
        // 提升效率，减小体积
        concatenateModules: true,
        minimizer: [
            new TerserPlugin({
                //不将注释提取到单独的文件中（不生成 webpack5 的）LICENSE 文件
                extractComments: false,
            }),
            new HtmlMinimizerPlugin(),
            new CssMinimizerPlugin()
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new CopyWebpackPlugin({
            patterns: [
                { from: 'public/favicon.ico' },
            ]
        }),
    ]
})